package DRCOMM;

import java.io.IOException;

import com.fasterxml.jackson.databind.ObjectMapper;

public class dr_ajax_answer{

    public int code=0;
    public String msg="";
    public Object data=null;
    public int count=-1;
    public Object etc=null;

    public dr_ajax_answer(int code,String msg){
        this.code=code;
        this.msg=msg;
    }

    public void set_data(Object data){
        this.data=data;
    }

    public String json_string(){
        String result="";
        ObjectMapper mapper = new ObjectMapper();
        try {
            result=mapper.writeValueAsString(this);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

    public static String sample_json_string(int code,String msg){
        String result="";
        dr_ajax_answer daa=new dr_ajax_answer(code, msg);
        ObjectMapper mapper = new ObjectMapper();
        try {
            result=mapper.writeValueAsString(daa);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

    public static void main(String[] args){
        dr_ajax_answer daa=new dr_ajax_answer(0, "");
        dr_menu dm=new dr_menu("c1", "", 1, "主菜单");
        dr_menu dm1=new dr_menu("c11", "channel/channel-list.html", 11, "通道管理");
        dm.add_children(dm1);
        daa.set_data(dm);
        System.out.println(daa.json_string());
    }
}